﻿using StructureMap;

namespace Sinbiota.Web.Initialization.StructureMap
{
    public class Bootstrapper : IBootstrapper
    {
        private static bool _hasStarted;



        public void BootstrapStructureMap()
        {

            ObjectFactory.Initialize(x =>
            {

                // We put the properties for an NHibernate ISession
                // in the StructureMap.config file, so this file
                // must be there for our application to
                // function correctly
                //x.UseDefaultStructureMapConfigFile = true;

                x.AddRegistry(new BusinessRegistry());
                x.AddRegistry(new PersistenceRegistry());
                x.AddRegistry(new WebServicesRegistry());

            });
        }

        public static void Restart()
        {
            if (_hasStarted)
            {
                ObjectFactory.ResetDefaults();
            }
            else
            {
                Bootstrap();
                _hasStarted = true;
            }
        }

        public static void Bootstrap()
        {
            new Bootstrapper().BootstrapStructureMap();
        }
    }
}